package gat.convertor.dic;

import java.util.List;

import org.mapstruct.Mapper;

import com.bitsun.core.common.convertor.IConvertor;
import com.bitsun.core.common.persistence.Pager;
import com.google.common.collect.Lists;

import cn.hutool.core.collection.CollectionUtil;
import gat.domain.model.dic.DicDataEntity;
import gat.dto.res.dic.DicDataResDto;
import gat.dto.res.dic.DicDataVo;
import gat.infrastructure.persistence.po.dic.DicDataPo;

/**
 * 
 * @author: tmac
 * @email: tmac
 */

@Mapper(componentModel = "spring")
public abstract class DicDataResDtoConvertor implements IConvertor<DicDataResDto, DicDataEntity, DicDataPo> {

    public Pager<DicDataResDto> convertPoPager2ResDtoPager(Pager<DicDataPo> poPager) {
        if (poPager == null) {
            return null;
        }

        Pager<DicDataResDto> resDtoPager = new Pager();
        resDtoPager.setTotalCount(poPager.getTotalCount());
        resDtoPager.setPageSize(poPager.getPageSize());
        resDtoPager.setTotalPage(poPager.getTotalPage());
        resDtoPager.setCurrentPage(poPager.getCurrentPage());
        resDtoPager.setList(poList2DtoList(poPager.getList()));

        return resDtoPager;
    }

    public List<DicDataVo> poList2VoList(List<DicDataPo> list) {
        List<DicDataVo> result = Lists.newArrayList();
        if (CollectionUtil.isEmpty(list)) {
            return result;
        }
        list.forEach(l -> {
            result.add(po2Vo(l));
        });
        return result;
    }

    public static DicDataVo po2Vo(DicDataPo po) {
        DicDataVo dicDataVo = new DicDataVo();
        dicDataVo.setId(po.getId());
        dicDataVo.setTypeCode(po.getTypeCode());
        dicDataVo.setCode(po.getCode());
        dicDataVo.setDescription(po.getDescription());
        dicDataVo.setSort(po.getSort());
        return dicDataVo;
    }
}
